#include "itemhandler.h"

ItemHandler::ItemHandler(QObject *parent) :
    QObject(parent)
{
}

void ItemHandler::addResource(Resource *resource)
{
    Q_ASSERT(resource != 0);

    resources.insert(resource->getId(), resource);
}

Resource * ItemHandler::getResource(int id)
{
    Q_ASSERT(0 <= id);

    if(resources.find(id) != resources.end())
        return resources.find(id).value();
    else
        return 0;
}

void ItemHandler::removeResource(int id)
{
    Q_ASSERT(0 <= id);

    resources.remove(id);
}

void ItemHandler::addCategory(Category *category)
{
    Q_ASSERT(category != 0);

    categories.insert(category->getId(), category);
}

Category * ItemHandler::getCategory(int id)
{
    Q_ASSERT(0 <= id);

    if(categories.find(id) != categories.end())
        return categories.find(id).value();
    else
        return 0;
}

void ItemHandler::removeCategory(int id)
{
    Q_ASSERT(0 <= id);

    categories.remove(id);
}
